package com.song.ssm.ssmvueproject.service.impl;

import com.song.ssm.ssmvueproject.entity.TAdmin;
import com.song.ssm.ssmvueproject.mapper.TAdminDao;
import com.song.ssm.ssmvueproject.service.TAdminService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;



/**
 * (TAdmin)表服务实现类
 *
 * @author makejava
 * @since 2024-04-03 10:01:09
 */
@Service("tAdminService")
public class TAdminServiceImpl implements TAdminService {
    @Resource
    private TAdminDao tAdminDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public TAdmin queryById(Integer id) {
        return this.tAdminDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param tAdmin 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<TAdmin> queryByPage(TAdmin tAdmin, PageRequest pageRequest) {
        long total = this.tAdminDao.count(tAdmin);
        return new PageImpl<>(this.tAdminDao.queryAllByLimit(tAdmin, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param tAdmin 实例对象
     * @return 实例对象
     */
    @Override
    public TAdmin insert(TAdmin tAdmin) {
        this.tAdminDao.insert(tAdmin);
        return tAdmin;
    }

    /**
     * 修改数据
     *
     * @param tAdmin 实例对象
     * @return 实例对象
     */
    @Override
    public TAdmin update(TAdmin tAdmin) {
        this.tAdminDao.update(tAdmin);
        return this.queryById(tAdmin.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.tAdminDao.deleteById(id) > 0;
    }
}
